package com.othershe.nicedialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 模块说明：
 *
 * @author 陈浩
 * @date 2017/12/15
 */

public class ShareDialog extends NiceDialog {
    private ShareDialogClickListener dialogClickListener;

    private static Context mContext;
    private String cancelText = "取消";//取消按钮内容
    private int cancelTextColor;//取消按钮字体颜色
    private int cancelTextSize = 16;//取消按钮字体大小

    public static ShareDialog newInstance(Context context) {
        mContext = context;
//        Bundle bundle = new Bundle();
//        bundle.putString("type", type);
        ShareDialog dialog = new ShareDialog();
        dialog.setShowBottom(true);
        dialog.setOutCancel(true);
//        dialog.setArguments(bundle);
        return dialog;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        Bundle bundle = getArguments();
//        if (bundle == null) {
//            return;
//        }
//        type = bundle.getString("type");
    }

    @Override
    public int intLayoutId() {
        return R.layout.share_layout;
    }


    public ShareDialog setCancelText(String resId) {
        this.cancelText = resId;
        return this;
    }

    public ShareDialog setCancelTextColor(int resId) {
        this.cancelTextColor = mContext.getResources().getColor(resId);
        return this;
    }

    public ShareDialog setCancelTextSize(int size) {
        this.cancelTextSize = size;
        return this;
    }


    @Override
    public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {
        TextView cancelView = holder.getView(R.id.tv_cancel);
//        LinearLayout llqq = holder.getView(R.id.ll_qq);
//        LinearLayout ll_wechat = holder.getView(R.id.ll_wechat);
//        LinearLayout ll_weibo = holder.getView(R.id.ll_weibo);
//        LinearLayout ll_moment = holder.getView(R.id.ll_moment);

        if (cancelTextSize > 0)
            cancelView.setTextSize(cancelTextSize);
        if (!cancelText.equals(""))
            cancelView.setText(cancelText);
        if (cancelTextColor > 0)
            cancelView.setTextColor(cancelTextColor);
        holder.setOnClickListener(R.id.ll_qq, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickListener != null)
                    dialogClickListener.setOnItemClickListener(dialog, v, 0);
//                dialog.dismiss();
            }
        });

        holder.setOnClickListener(R.id.ll_weibo, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickListener != null)
                    dialogClickListener.setOnItemClickListener(dialog, v, 1);
            }
        });
        holder.setOnClickListener(R.id.ll_wechat, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickListener != null)
                    dialogClickListener.setOnItemClickListener(dialog, v, 2);
            }
        });
        holder.setOnClickListener(R.id.ll_moment, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (dialogClickListener != null)
                    dialogClickListener.setOnItemClickListener(dialog, v, 3);
            }
        });
        holder.setOnClickListener(R.id.tv_cancel, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    @Override
    public ShareDialog setOutCancel(boolean outCancel) {
        super.setOutCancel(outCancel);
        return this;
    }

    @Override
    public ShareDialog show(FragmentManager manager) {
        super.show(manager);
        return this;
    }

    public interface ShareDialogClickListener {
        void setOnItemClickListener(BaseNiceDialog dialog, View view, int position);
    }

    public void setShareDialogClickListener(ShareDialogClickListener onItemClickListener) {
        this.dialogClickListener = onItemClickListener;
    }
}
